package moodish.Junit;

import static org.junit.Assert.*;
import moodish.dummy.ClientCommDummy;
import moodish.dummy.ServerCommDummy;

import org.junit.Before;
import org.junit.Test;

public class JUnitServerCommDummyTest {
	
	ServerCommDummy scd;
	ClientCommDummy ccd1;
	ClientCommDummy ccd2;

	@Before
	public void setUp() throws Exception {
		scd = new ServerCommDummy();
		ccd1 = new ClientCommDummy();
		ccd2 = new ClientCommDummy();
	
	}

	@Test
	public void test() {
		scd.start();
		ccd1.connect("localhost", "Sofia");
		ccd2.connect("localhost", "Margarida");
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		assertFalse(scd.clientIsConnected("CarolinaFrancisquina"));
//		assertFalse(scd.hasNextMessage());
		
		ccd1.sendMoodishMessage("Happy");
		assertTrue(scd.hasNextMessage());
		assertNotNull(scd.getNextMessage());
		
		scd.sendClientConnected("Margarida", "Joao");
		scd.sendError("Sofia", "There has been an error");
		scd.sendMoodishMessage("Sofia", "Margarida", "Happy");
		scd.sendNewFriendship("Sofia", "Margarida");
		scd.sendNewUnfriendship("Sofia", "Margarida");
		
		
		scd.disconnectClient("Sofia");
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		assertFalse(scd.clientIsConnected("Sofia"));
		scd.sendClientDisconnected("Margarida", "Sofia");		
	}

}
